﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Globalization;

namespace ISolutions.SharePoint.Mui.Helper
{
    public class MuiService
    {
        private MuiService()
        {
        }

        /// <summary>
        /// Singleton instance
        /// </summary>
        public static MuiService Instance = new MuiService();

        /// <summary>
        /// Gets the languages.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <returns></returns>
        public IEnumerable<MuiLanguage> GetLanguages(SPWeb web)
        {
            List<MuiLanguage> list = new List<MuiLanguage>();

            foreach (CultureInfo lang in SPContext.Current.Web.SupportedUICultures)
            {
                list.Add(new MuiLanguage() { DisplayName = lang.DisplayName, LanguageCode = lang.LCID });
            }

            return list;
        }

        /// <summary>
        /// Defaults the language.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <returns></returns>
        public MuiLanguage DefaultLanguage(SPWeb web)
        {
            return ( from l in GetLanguages(web)
                   where l.LanguageCode == web.Language
                   select l).First();
        }
    }
}
